<template>
    <div v-loading="loading" element-loading-text="拼命加载中">
        <div class="content_top">
            系统设置
        </div>
        <div class="content">
            <el-form ref="form" :model="form" :rules="rules" label-width="180px" size="mini">
                <el-form-item label="自动取消订单时长(秒)：" prop="autoCancelTime">
                    <el-input-number v-model="form.autoCancelTime" :min="0" style="width: 400px;"></el-input-number>
                </el-form-item>
                <el-form-item label="每天提现次数：" prop="dailyCashLimit">
                    <el-input-number v-model="form.dailyCashLimit" :min="0" style="width: 400px;"></el-input-number>
                </el-form-item>
                <el-form-item label="提现手续费百分比(%)：" prop="cashRate">
                    <el-input-number v-model="form.cashRate" :min="0" :precision="2"  style="width: 400px;"></el-input-number>
                </el-form-item>
                <el-form-item label="站长佣金固定比例(%)：" :precision="2" prop="siteFeeFixedRate">
                    <el-input-number v-model="form.siteFeeFixedRate" :min="0" style="width: 400px;"></el-input-number>
                </el-form-item>
                <el-form-item label="站长佣金浮动比例(%)：" :precision="2" prop="siteFeeFloatRate">
                    <el-input-number v-model="form.siteFeeFloatRate" :min="0" style="width: 400px;"></el-input-number>
                </el-form-item>
                <el-form-item label="订单退货时限(分钟)：" prop="orderReturnTimeLimit">
                    <el-input-number v-model="form.orderReturnTimeLimit" :min="0" style="width: 400px;"></el-input-number>
                </el-form-item>
                <el-form-item style="text-align: left">
                    <el-button type="primary" @click="onSubmit">保存</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>

    import {info, save} from "@/api/config/system";

    export default {
        name: 'system-config',
        data() {
            return {
                loading: false,
                form: {
                    dataRange: null,
                    startDate: null,
                    endDate: null,
                    amount: 0,
                    orderPriceLimit: 0,
                    validity: 0,
                    count: 0,
                    status: 2
                },
                rules: {
                    autoCancelTime: [
                        {required: true, message: '请输入自动取消订单时长', trigger: 'blur'},
                    ],
                    dailyCashLimit: [
                        {required: true, message: '请输入每天提现次数', trigger: 'blur'},
                    ],
                    cashRate: [
                        {required: true, message: '请输入提现手续费百分比', trigger: 'blur'},
                    ],
                    siteFeeFixedRate: [
                        {required: true, message: '请输入站长佣金固定比例', trigger: 'blur'},
                    ],
                    siteFeeFloatRate: [
                        {required: true, message: '请输入站长佣金浮动比例', trigger: 'blur'},
                    ],
                    orderReturnTimeLimit: [
                        {required: true, message: '请输入订单退货时限', trigger: 'blur'},
                    ],
                }
            }
        },
        mounted() {
            this.loadConfig()
        },
        methods: {
            async loadConfig() {
                this.loading = true
                let res = await info()
                this.loading = false
                this.form = res.data;
            },
            onSubmit() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.save()
                    } else {
                        return false;
                    }
                });
            },
            async save() {
                this.loading = true;
                let params = JSON.parse(JSON.stringify(this.form))
                let res = await save(params)
                this.loading = false
                if (res.code !== '0') {
                    return this.$notify.error({title: '消息', message: res.message})
                }
                this.$notify({title: '消息', message: '保存成功', type: 'success'});
            }
        }
    }
</script>

<style scoped>

</style>